package com.wuxiaoqin.server.controller;


import com.wuxiaoqin.server.entity.Orders;
import com.wuxiaoqin.server.entity.Users;
import com.wuxiaoqin.server.entity.order.OrdCreaParm;
import com.wuxiaoqin.server.entity.order.OrderList;
import com.wuxiaoqin.server.service.IOrdersService;
import com.wuxiaoqin.server.service.IUsersService;
import com.wuxiaoqin.uitls.respObj.RespBean;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2021-11-05
 */

@RestController
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    private IOrdersService ordersService;

    @Autowired
    private IUsersService usersService;
    //生成订单

    @ApiOperation(value = "生成订单")
    @PostMapping("/createorder")
    public RespBean createOrder(OrdCreaParm ordCreaParm) throws Exception {
        return ordersService.creatOrder(ordCreaParm);
    }

    @ApiOperation( value ="获取本用户订单List")
    @GetMapping("/getOrderByUserId")
    public RespBean getOrderByUserId()  {
        Users currentUser = usersService.getCurrentUser();
        return ordersService.getOrderByUserId(currentUser.getUId());
    }
    @ApiOperation(value ="通过id获取订单One")
    @GetMapping("/getOrderById")
    public RespBean getOrderById(@RequestParam("id") Integer orderid)  {
        Users currentUser = usersService.getCurrentUser();
        return ordersService.getOrderById(currentUser.getUId(),orderid);
    }

    @ApiOperation(value = "通过id获取订单的商品")
    @GetMapping("/getOrderGoods")
    public RespBean getOrderGoods(@RequestParam("id") Integer orderid)  {
        Users currentUser = usersService.getCurrentUser();

        return ordersService.getOrderGoods(currentUser.getUId(),orderid);
    }
    @ApiOperation(value = "获取已发货的订单")
    @GetMapping("/getOrderFaHuo")
    public List<Orders> getOrderFaHuo()  {
        Users currentUser = usersService.getCurrentUser();
        return ordersService.getOrderFaHuo(currentUser.getUId());
    }

    @ApiOperation(value = "确认收货")
    @GetMapping("/verifyShouHuo")
    public RespBean verifyShouHuo(@RequestParam("orderNo") Integer orderNo)  {
        Users currentUser = usersService.getCurrentUser();
        return ordersService.verifyShouHuo(currentUser.getUId(),orderNo);
    }


}
